package com.fwh.web.utils.aop;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Author: fwh
 * @date 2019/4/11&& 15:33
 */
@Slf4j
@Aspect
@Component
//Caused by: java.lang.ClassNotFoundException: org.aspectj.util.PartialOrder$PartialComparable
public class WebAspect {

    @Pointcut("execution(public * com.fwh.web.service.*.*(..))")
    public void aspect(){
    }

    @Before("aspect()")
    public void before(JoinPoint joinpoint){
        log.info("i am a before aspect method fwh...");
        log.info("请求接口类型为:{}",joinpoint.getSignature().getDeclaringType());
        log.info("请求接口方法为:{}",joinpoint.getSignature().getName());
        log.info("请求接口参数为:{}", JSONUtil.toJsonStr(joinpoint.getArgs()));
    }
    @AfterReturning("aspect()")
    public void afterReturning(){
        log.info("i am a afterReturning ascpet method fwh...");
    }

    @AfterThrowing(value = "aspect()",throwing = "e")
    public void afterThrowing(Throwable e){
        log.info("i am a afterThrowing ascpet method fwh...异常为:{}",e);
    }
}
